home *** CD-ROM | disk | FTP | other *** search
- unit TabActns;
-
- interface
-
- uses
- ActnList, Classes, ComCtrls;
-
- type
- TTabAction = class(TAction)
- private
- FTabControl: TCustomTabControl;
- protected
- procedure SetTabControl(Value: TCustomTabControl);
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- public
- function HandlesTarget(Target: TObject): Boolean; override;
- procedure UpdateTarget(Target: TObject); override;
- published
- property TabControl: TCustomTabControl read FTabControl write SetTabControl;
- end;
-
- TNextTabAction = class(TTabAction)
- public
- procedure ExecuteTarget(Target: TObject); override;
- end;
-
- TPriorTabAction = class(TTabAction)
- public
- procedure ExecuteTarget(Target: TObject); override;
- end;
-
- implementation
-
- { TTabAction }
-
- procedure TTabAction.SetTabControl(Value: TCustomTabControl);
- begin
- if Value <> FTabControl then
- begin
- FTabControl := Value;
- //If we have a target control, request notification
- //so we will be told if it is destroyed
- if Assigned(Value) then
- Value.FreeNotification(Self)
- end;
- end;
-
- procedure TTabAction.Notification(AComponent: TComponent;
- Operation: TOperation);
- begin
- //Set target control property to nil if target is destroyed
- if (AComponent = FTabControl) and (Operation = opRemove) then
- FTabControl := nil
- end;
-
- function TTabAction.HandlesTarget(Target: TObject): Boolean;
- begin
- //If we have a specific target and it matches
- //the passed control, we will accept it
- if Target = FTabControl then
- Result := True
- else
- //If we have no specific target, but the passed
- //control is of an acceptable type, then we accept it
- if (FTabControl = nil) and
- ((Target is TTabControl) or
- (Target is TPageControl)) then
- Result := True
- else
- Result := False;
- end;
-
- procedure TTabAction.UpdateTarget(Target: TObject);
- begin
- //Make sure tab control has more than one tab
- if Target is TTabControl then
- Enabled := TTabControl(Target).Tabs.Count > 1
- else
- //Make sure page control has more than one page
- if Target is TPageControl then
- Enabled := TPageControl(Target).PageCount > 1
- else
- //No other TCustomTabControl derivative is understood
- Enabled := False;
- end;
-
- { TPriorTabAction }
-
- procedure TPriorTabAction.ExecuteTarget(Target: TObject);
- begin
- if Target is TTabControl then
- with TTabControl(Target) do
- TabIndex := (TabIndex - 1 + Tabs.Count) mod Tabs.Count
- else
- if Target is TPageControl then
- with TPageControl(Target) do
- ActivePage :=
- Pages[(ActivePage.TabIndex - 1 + PageCount) mod PageCount]
- end;
-
- { TNextTabAction }
-
- procedure TNextTabAction.ExecuteTarget(Target: TObject);
- begin
- if Target is TTabControl then
- with TTabControl(Target) do
- TabIndex := (TabIndex + 1) mod Tabs.Count
- else
- if Target is TPageControl then
- with TPageControl(Target) do
- ActivePage := Pages[(ActivePage.TabIndex + 1) mod PageCount]
- end;
-
- end.
-